package cn.wilson;

import cn.wilson.config.RabbitmqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Rev {
    //监听邮件的队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receiveEmail(String msg, Message message, Channel channel) throws IOException {
        System.out.println("-------邮件------------");
        System.out.println("邮件消息的内容：" + msg);
        System.out.println("邮件消息的内容：" + message.getBody());
        System.out.println("邮件消息id：" + message.getMessageProperties().getConsumerTag());
        System.out.println(msg);
        //手动签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

    //监听短信的队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_SMS})
    public void receiveSms(String msg, Message message, Channel channel) throws IOException {
        System.out.println("-------短信------------");
        System.out.println("短信消息的内容：" + msg);
        System.out.println("短信消息的内容：" + message.getBody());
        System.out.println("短信消息id：" + message.getMessageProperties().getConsumerTag());
        System.out.println(msg);
        //手动签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
} 